#include "PsoVelocityClampingMethods.h"

#include "MathUtil.h"

#include <math.h>

namespace jcrada {

    void BasicVelocityClamping::clamp( PsoParticle& particle ) {
        for (int i = 0; i < particle.getSize(); ++i) {
            if (Math::abs(particle.getVelocity(i) > particle.getMaxVelocity(i))) {
                particle.setVelocity(i,
                        GSL_SIGN(particle.getVelocity(i)) * particle.getMaxVelocity(i));
            }
        }
    }

    void TanhVelocityClamping::clamp( PsoParticle& particle ) {
        for (int i = 0; i < particle.getSize(); ++i) {
            particle.setVelocity(i, particle.getMaxVelocity(i) *
                    tanh(particle.getVelocity(i) / particle.getMaxVelocity(i)));
        }
    }
}
